package com.qire.manhua.dal.dao;

import com.qire.common.dal.dao.IDao;
import com.qire.manhua.model.po.LocalComicChapter;
import java.util.List;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Query;

@Dao
public interface ComicChapterDao extends IDao<LocalComicChapter> {

    @Query("SELECT * FROM LocalComicChapter")
    List<LocalComicChapter> queryAll();

    @Query("SELECT * FROM LocalComicChapter WHERE comicId = :comicId")
    List<LocalComicChapter> queryListBy(int comicId);

    /**
     * 通过章节ID数组在数据库中查找章节List
     * @param chapterIds int 数组，需要注意的是只能绑定999个条目到查询，这是SQLite的一个限制
     * @return 章节列表
     */
    @Query("SELECT * FROM LocalComicChapter WHERE id IN(:chapterIds)")
    List<LocalComicChapter> queryListIn(int... chapterIds);

    @Query("SELECT * FROM LocalComicChapter WHERE id = :chapterId")
    LocalComicChapter queryBy(int chapterId);

    @Delete(entity = LocalComicChapter.class)
    void deleteByComic(ComicId... comicId);

    class ComicId {
        public final int comicId;
        public ComicId(int comicId) {
            this.comicId = comicId;
        }
    }
}
